<?php
/**
 * Nordic Repository
 * 
 * LICENSE
 * 
 * The new BSD license is applied on this source-file. For further
 * information please visit http://license.nordic-dev.de/newbsd.txt
 * or send an email to andre.moelle@gmail.com.
 */

/**
 * Necessary includes.
 */
Zend_Loader::loadClass('Zend_Db_Adapter_Abstract');

/**
 * Class that glues the underlying models together.
 * 
 * @category   Nordic
 * @package    Nordic_Auth
 * @copyright  2007 Nordic Development
 * @license    http://license.nordic-dev.de/newbsd.txt (New-BSD license)
 * @author     Andre Moelle <andre.moelle@gmail.com>
 * @version    $Id: Model.php 3 2007-07-08 09:21:42Z andre.moelle $
 */
class Nordic_Auth_Model
{
	/**
	 * Instance of the database-instance.
	 * 
	 * @var Zend_Db_Adapter_Abstract
	 */
	private $_db;
	
	/**
	 * Model-objects that should be glued together.
	 * 
	 * @var array
	 */
	private $_glue = array(
		'Nordic_Auth_Model_User' => null,
		'Nordic_Auth_Model_Token' => null
	);
	
	/**
	 * Constructor makes the object ready.
	 * 
	 * @param array $options contains model-objects
	 * @return void
	 */
	public function __construct (Zend_Db_Adapter_Abstract $db, array $options = array())
	{
		foreach($this->_glue as $class => $instance)
		{
			foreach($options as $option)
			{
				if(!is_object($option))
				{
					continue;
				}
				
				if($option instanceof $class)
				{
					$this->_glue[$class] = $option;
					continue 2;
				}
			}
			
			Zend_Loader::loadClass($class);
			$this->_glue[$class] = new $class();
		}
		
		$this->_db = $db;
	}
	
	/**
	 * Returns the user-object.
	 * 
	 * @param void
	 * @return Nordic_Auth_Model_User
	 */
	public function getUser ()
	{
		return $this->_glue['Nordic_Auth_Model_User'];
	}
	
	/**
	 * Returns the token-object.
	 * 
	 * @param void
	 * @return Nordic_Auth_Model_Token
	 */
	public function getToken ()
	{
		return $this->_glue['Nordic_Auth_Model_Token'];
	}
}
?>